/*  Game Editor for yALB - Yet Another List Builder (roster Editor for Wargames/tabletop games).
    Copyright (C) 2008-2012  Daniel Ricardo Castro Alvarado

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

#ifndef GAMEEDITOR_H
#define GAMEEDITOR_H

#include <QMainWindow>
#include <QActionGroup>
#include <QTranslator>

#include "other/gameStructs.h"

#include "widgets/itemselector.h"
#include "widgets/propertyform.h"
#include "widgets/categorywidget.h"
#include "widgets/columnwidget.h"
#include "widgets/propertywidget.h"
#include "widgets/optionwidget.h"
#include "widgets/itemwidget.h"
#include "widgets/globaltextwidget.h"

#include "collections/categorycollection.h"
#include "collections/columncollection.h"
#include "collections/propertycollection.h"
#include "collections/optioncollection.h"
#include "collections/itemcollection.h"
#include "collections/globaltextcollection.h"

namespace Ui {
    class GameEditor;
}

class GameEditor : public QMainWindow
{
    Q_OBJECT

public:
    explicit GameEditor(QWidget *parent = 0);
    ~GameEditor();

protected:
    void closeEvent(QCloseEvent *event);
    void changeEvent(QEvent *event);

private:
    void loadLanguage(QString language);

    bool unsavedFileMessage();
    void newGameFile();
    bool saveGameFile(const QString& path);
    bool openGameFile(const QString& path);
    void setSaved(bool saved);

    Ui::GameEditor *ui;
    QActionGroup *languageGroup;
    QTranslator qtTranslator;
    QTranslator editorTranslator;
    QString currentLanguage;

    ItemSelector *itemSelector;

    QString savedFile;
    bool isSaved;

    CategoryCollection unitCategories;
    CategoryWidget *unitCategoryWidget;
    CategoryCollection itemCategories;
    CategoryWidget *itemCategoryWidget;
    CategoryCollection optionCategories;
    CategoryWidget *optionCategoryWidget;
    ColumnCollection columnCollection;
    ColumnWidget *columnWidget;

    PropertyCollection unitProperties;
    PropertyWidget *unitPropertyWidget;
    PropertyCollection itemProperties;
    PropertyWidget *itemPropertyWidget;
    PropertyCollection optionProperties;
    PropertyWidget *optionPropertyWidget;

    OptionCollection options;
    OptionWidget *optionWidget;

    ItemCollection items;
    ItemWidget *itemWidget;

    GlobalTextCollection globalTexts;
    GlobalTextWidget *textWidget;

private slots:
    void languageChanged(QAction *action);

    void on_actionNew_triggered();
    void on_actionOpen_triggered();
    void on_actionSave_triggered();
    void on_actionSaveAs_triggered();
    void on_actionExit_triggered();

    inline void setUnsaved() {
        setSaved(false);
    }
};

#endif // GAMEEDITOR_H
